home *** CD-ROM | disk | FTP | other *** search
/ Risc World 5 / Risc World 5.iso / SOFTWARE / Issue3 / Games / xrick / !xrick / src / c / system < prev    next >
Text File  |  2004-06-24  |  2KB  |  132 lines

  1. /*
  2.  * xrick/src/system.c
  3.  *
  4.  * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
  5.  *
  6.  * The use and distribution terms for this software are contained in the file
  7.  * named README, which can be found in the root of this distribution. By
  8.  * using this software in any fashion, you are agreeing to be bound by the
  9.  * terms of this license.
  10.  *
  11.  * You must not remove this notice, or any other, from this software.
  12.  */
  13.  
  14. #include <SDL.h>
  15.  
  16. #include <stdarg.h>   /* args for sys_panic */
  17. #include <fcntl.h>    /* fcntl in sys_panic */
  18. #include <stdio.h>    /* printf */
  19. #include <stdlib.h>
  20. #include <signal.h>
  21.  
  22. #include "system.h"
  23.  
  24. /*
  25.  * Panic
  26.  */
  27. void
  28. sys_panic(char *err, ...)
  29. {
  30.   va_list argptr;
  31.   char s[1024];
  32.  
  33.   /* change stdin to non blocking */
  34.   /*fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);*/
  35.   /* NOTE HPUX: use ... is it OK on Linux ? */
  36.   /* fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NDELAY); */
  37.  
  38.   /* prepare message */
  39.   va_start(argptr, err);
  40.   vsprintf(s, err, argptr);
  41.   va_end(argptr);
  42.  
  43.   /* print message and die */
  44.   printf("%s\npanic!\n", s);
  45.   exit(1);
  46. }
  47.  
  48.  
  49. /*
  50.  * Print a message
  51.  */
  52. void
  53. sys_printf(char *msg, ...)
  54. {
  55.   va_list argptr;
  56.   char s[1024];
  57.  
  58.   /* change stdin to non blocking */
  59.   /*fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);*/
  60.   /* NOTE HPUX: use ... is it OK on Linux ? */
  61.   /* fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NDELAY); */
  62.  
  63.   /* prepare message */
  64.   va_start(argptr, msg);
  65.   vsprintf(s, msg, argptr);
  66.   va_end(argptr);
  67.   printf(s);
  68. }
  69.  
  70. /*
  71.  * Return number of microseconds elapsed since first call
  72.  */
  73. U32
  74. sys_gettime(void)
  75. {
  76.   static U32 ticks_base = 0;
  77.   U32 ticks;
  78.  
  79.   ticks = SDL_GetTicks();
  80.  
  81.   if (!ticks_base)
  82.     ticks_base = ticks;
  83.  
  84.   return ticks - ticks_base;
  85. }
  86.  
  87. /*
  88.  * Sleep a number of microseconds
  89.  */
  90. void
  91. sys_sleep(int s)
  92. {
  93.   SDL_Delay(s);
  94. }
  95.  
  96. /*
  97.  * Initialize system
  98.  */
  99. void
  100. sys_init(int argc, char **argv)
  101. {
  102.     sysarg_init(argc, argv);
  103.     sysvid_init();
  104. #ifdef ENABLE_JOYSTICK
  105.     sysjoy_init();
  106. #endif
  107. #ifdef ENABLE_SOUND
  108.     if (sysarg_args_nosound == 0)
  109.         syssnd_init();
  110. #endif
  111.     atexit(sys_shutdown);
  112.     signal(SIGINT, exit);
  113.     signal(SIGTERM, exit);
  114. }
  115.  
  116. /*
  117.  * Shutdown system
  118.  */
  119. void
  120. sys_shutdown(void)
  121. {
  122. #ifdef ENABLE_SOUND
  123.     syssnd_shutdown();
  124. #endif
  125. #ifdef ENABLE_JOYSTICK
  126.     sysjoy_shutdown();
  127. #endif
  128.     sysvid_shutdown();
  129. }
  130.  
  131. /* eof */
  132.